﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Demo623
{
    public partial class Regist : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            //获取各个参数 准备添加到数据库
            string name = TextBox1.Text;
            string password = TextBox2.Text;
            int gender = RadioButton1.Checked ? 0 : 1;  //判断单选1是否被选中 true则赋值0 false则赋值1
            string email = TextBox3.Text;

            //准备一条sql语句  
            string sql = "INSERT INTO StudentInfo(stu_name,gender,email,password) VALUES (@name,@gender,@email,@password)";
           //创建一个sql参数数组 准备接收对应参数
            SqlParameter[] pars = {
                new SqlParameter("name",name),
                new SqlParameter("gender",gender),
                new SqlParameter("email",email),
                new SqlParameter("password",password)
            };
            //创建SQL工具类对象  
            SQLHelper helper = new SQLHelper();
            //调用工具类中的方法 传递语句和参数 并接收返回结果
            int result= helper.Add(sql, pars);
            //如果结果不为-1则语句执行成功 （不严谨但不想改）
            if (result!=-1)
            {
                //
                Literal1.Text = "注册成功！<a href=\"Login.aspx\">点此去登录</a>";
            }
        }
    }
}